package hulppakket;

import java.io.Serializable;

public class Vector3f extends Tuple3f implements Serializable {

	private static final long serialVersionUID = -6786788616225127553L;

	/**
	 * Constructs and initializes a Vector3f to (0,0,0).
	 */
	public Vector3f() {
	}

	/**
	 * Constructs and initializes a Vector3f from the array of length 3.
	 * 
	 * @param v
	 */
	public Vector3f(float v[]) {
		super(v);
	}

	/**
	 * Constructs and initializes a Vector3f from the specified xyz coordinates.
	 * 
	 * @param x
	 * @param y
	 * @param z
	 */
	public Vector3f(float x, float y, float z) {
		super(x, y, z);
	}

	/**
	 * Constructs and initializes a Vector3f from the specified Tuple3f.
	 * 
	 * @param t
	 */
	public Vector3f(Tuple3f t) {
		super(t);
	}

	/**
	 * Constructs and initializes a Vector3f from the specified Vector3f
	 * 
	 * @param v
	 */
	public Vector3f(Vector3f v) {
		super(v);
	}

	public Vector3f add(Vector3f other) {
		float x, y, z;
		x = this.x + other.x;
		y = this.y + other.y;
		z = this.z + other.z;
		return new Vector3f(x, y, z);
	}

	public Vector3f crossProduct(Vector3f other) {
		float x, y, z;
		x = (this.y * other.z) - (this.z * other.y);
		y = (this.z * other.x) - (this.x * other.z);
		z = (this.x * other.y) - (this.y * other.x);
		return new Vector3f(x, y, z);
	}

	public float dotProduct(Vector3f other) {
		return (this.x * other.x) + (this.y * other.y) + (this.z * other.z);
	}

	public float length() {
		return (float) Math.sqrt(this.dotProduct(this));
	}

	public Vector3f normalize() {
		float length = this.length();
		length = 1 / length;
		float x, y, z;
		x = this.x * length;
		y = this.y * length;
		z = this.z * length;
		return new Vector3f(x, y, z);
	}

	public Vector3f scale(float scalar) {
		return new Vector3f(this.x * scalar, this.y * scalar, this.z * scalar);
	}

	public Vector3f substract(Point3f other) {
		return new Vector3f(this.x - other.x, this.y - other.y, this.z
				- other.z);
	}

	public Vector3f substract(Vector3f other) {
		return new Vector3f(this.x - other.x, this.y - other.y, this.z
				- other.z);
	}
}
